package cn.sytton.taffecloud.service.file.controller;

import cn.sytton.taffecloud.common.base.security.LoginUser;
import cn.sytton.taffecloud.common.base.util.JsonUtil;
import cn.sytton.taffecloud.common.base.util.SecurityUtil;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试Openfeign调用
 *
 * @author skyrock
 */
@RestController
@RequestMapping("/test")
public class ApiTestController {

//    @GetMapping("/{path}")
//    public TestModel getTest(@PathVariable String path) {
//        TestModel tm = new TestModel();
//        tm.setId(SecurityUtil.getUserId());
//        tm.setName("getTest");
////        if ("admin".equals(tm.getId())) {
////            //异常测试
////            throw new BizException("biz exception");
////        }
//        //调用超时测试
//        try {
//            Thread.sleep(90000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        return tm;
//    }
    @PostMapping("/{path}")
    public String postTest(@PathVariable String path) {
        return  "postTest " + path;
    }

//    @GetMapping("/query/{path}")
//    public List<TestModel> getTestQuery(@PathVariable String path, LoginUser testUser) {
//        TestModel tm = new TestModel();
//        tm.setName("getTestQuery 1");
//
//        TestModel tm2 = new TestModel();
//        tm2.setName("getTestQuery 2");
//
//        List<TestModel> list = new ArrayList<>();
//        list.add(tm);
//        list.add(tm2);
//        return list;
//    }
    @PostMapping("/body/{path}")
    public void postTestBody(@PathVariable String path, @RequestBody LoginUser testUser) {
        String r = "post test-body file feign " + JsonUtil.getString(testUser);
        System.out.println(r);
    }

    @PostMapping("/body2/{path}")
    public void postTestBody2(@PathVariable String path, @RequestBody LoginUser testUser) {
        System.out.println(testUser.getUserId());
        String r = "post test-body 2 file feign " + JsonUtil.getString(testUser);
        System.out.println(r);
    }
}
